﻿using UnityEngine;
using UnityEngine.UI;

public class Cell : MonoBehaviour
{
    public GameObject letterText;
    public string letter;
    public Position position;
    public bool _isShown;

    public bool IsShown
    {
        get { return GameState.mainCells[position]._isShown; }
        set { GameState.mainCells[position]._isShown = value; }
    }

    public void Animate()
    {
        ShowText();
        letterText.transform.localScale = Vector3.zero;
        letterText.GetComponent<Animator>().SetTrigger("show");
    }

    public void ShowAnswer()
    {
        GameState.mainCells[position].IsShown = true;
        GameState.mainCells[position].Animate();
    }

    public void ShowText()
    {
        letterText.SetActive(true);
        letterText.GetComponentInChildren<Text>().text = letter;
    }

    public void OnCellClick()
    {
        if (GameState.enablePickBox && !IsShown)
        {
            GameState.enablePickBox = false;
            ShowAnswer();
        }
    }
}
